package com.cfh.microserviceconsumermovie.fallbackconfig;

import com.cfh.microserviceapi.domain.User;
import com.cfh.microserviceconsumermovie.service.UserFeignClient;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 用户降级 Factory
 *
 * @author chenfh
 * @date 2019/7/17
 */
@Component
public class FeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public UserFeignClient create(Throwable throwable) {
        return new UserFeignClient() {
            @Override
            public User findById(Long id) {
                logger.info("UserFeignClient#findById fallbackconfig cause by : " + throwable);
                User user = new User();
                user.setId(-1L);
                user.setName("默认用户a");
                return user;
            }
        };
    }
}
